<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/27 0027
 * Time: 下午 8:00
 */
namespace app\common\model;

use think\Model;

class Tenantdistributiontype extends BaseModel {
    protected $resultSetType = 'collection';

    const D_TYPE_0 = 0;    //物流配送
    const D_TYPE_1 = 1;    //到店自取
    const D_TYPE_2 = 2;    //物流配送
    const D_TYPE_3 = 3;    //到店自取

    const DISTRIBUTIONTYPE_1 = 1;  //1自取    2物流
    const DISTRIBUTIONTYPE_2 = 2;



    /**
     * @return \think\model\relation\HasOne
     * 获取商户店铺关联
     */
    public function Stores()
    {
        return $this->hasOne('store','tenantId','id');
    }



    public function getlogistics()
    {
        return $this->hasOne('logistics',"t_type_id","id");
    }


    /**
     *根据typeid获取对应的物流配置信息
     */
    public function findDistributionType($typeId){
        return self::where([
            'id'=>$typeId,
            "distributionType"=>self::DISTRIBUTIONTYPE_2
        ])->find();
    }

    /**
     * @param $tenantId
     * @return array|false|\PDOStatement|string|Model
     * 获取当前商铺所关联的物流信息
     */
    public function getTDT($tenantId){
         return self::hasWhere('getlogistics', ['tenantId'=>$tenantId,"tenantdistributiontype.distributionType"=>self::D_TYPE_2])->find();
    }


    public function updateDistributionType($param){
        $id = $param['id'];
        unset($param['id']);
        $updateDate = date("Y-m-d h:i:s");
        $param['updateDate'] = $updateDate;
        return self::where("id",'=',$id)->update($param);
    }


}